package com.aaa.service.sds.impl;

import com.aaa.aspect.InsertAnn;
import com.aaa.aspect.UpdateAnn;
import com.aaa.entity.PageSortEntity;
import com.aaa.dao.sds.QuestionSdsDao;
import com.aaa.entity.sds.QuestionSds;
import com.aaa.service.sds.QuestionSdsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 问题表(TblQuestionSds)表服务实现类
 *
 * @author makejava
 * @since 2022-08-30 10:35:12
 */
@Service("tblQuestionSdsService")
public class QuestionSdsServiceImpl implements QuestionSdsService {
    @Resource
    private QuestionSdsDao questionSdsDao;

    /**
     * @param pageSortEntity
     * @param questionSds
     * @return
     * @create by: 张恒
     * @description: 查询所有
     * @create time: 2022/8/31 9:54
     */
    @Override
    public Page queryQuestionSdsPage(PageSortEntity pageSortEntity, QuestionSds questionSds) {
        //分页加排序
        PageHelper.startPage(pageSortEntity.getPage(), pageSortEntity.getLimit(), pageSortEntity.getOrderString());
        List<Map<String, Object>> mapList = questionSdsDao.queryQuestionSdsPage(questionSds);
        //强转为page
        Page page = (Page) mapList;
        return page;
    }


    /**
     * @param questionSds
     * @return
     * @create by: 张恒
     * @description: 添加
     * @create time: 2022/8/31 9:27
     */
    @InsertAnn
    @Override
    public boolean insertQuestion(QuestionSds questionSds) {
        return questionSdsDao.insertQuestion(questionSds);
    }


    /**
     * @param questionSds
     * @return
     * @create by: 张恒
     * @description: 修改
     * @create time: 2022/8/31 9:30
     */
    @UpdateAnn
    @Override
    public boolean updateQuestion(QuestionSds questionSds) {
        return questionSdsDao.updateQuestion(questionSds);
    }


    /**
     * @param id
     * @return
     * @create by: 张恒
     * @description: 删除
     * @create time: 2022/8/31 9:31
     */
    @Override
    public boolean deleteQuestionById(Integer[] id) {
        return questionSdsDao.deleteQuestionById(id);
    }


    /**
     * @param questionSds
     * @return
     * @create by: 张恒
     * @description: 添加修改时的唯一效验
     * @create time: 2022/8/31 18:44
     */
    @Override
    public boolean repetitionName(QuestionSds questionSds) {
        Integer integer = questionSdsDao.repetitionName(questionSds);
        if (integer > 0) {
            return false;
        }
        return true;
    }

}
